package xyj.sparrow.scheduler.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 返回类
 *
 * @author 江南小俊
 * @since 2021-06-04 11:02
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;


    public Result(T data) {
        this(200, "success", data);
    }

    public static Result<Object> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(data);
    }

    public static Result<Object> error(String msg) {
        return new Result<>(ResultCode.ERROR.getCode(), msg, null);
    }

    public static Result<Object> error(ResultCode error) {
        return new Result<>(error.getCode(), error.getMsg(), null);
    }
}
